﻿using System.Collections.Generic;
using System.Linq;
using yiCommerce.Core.Data;
using yiCommerce.Core.Domain.Shops;
using yiCommerce.Service.Products;

namespace yiCommerce.Service.Shops
{
    public class ShopService : IShopService
    {

        private IRepository<Shop> _shopRep;

        private IProductService _productService;

        public ShopService(IRepository<Shop> shopRep, IProductService productService)
        {
            _shopRep = shopRep;
            _productService = productService;
        }

        public Shop GetShopById(int shopId)
        {
            var query = from s in _shopRep.Table
                        where s.Id == shopId
                        select s;

            var shop = query.SingleOrDefault();
            if (shop != null)
            {

                return new Shop()
                    {
                        CustomerId = shop.CustomerId,
                        ShopName = shop.ShopName,
                        Products = _productService.GetAllProductsByShopPid(shopId),

                    };
            }
            else
            {
                return null;
            }
        }

        public IList<Shop> GetAllShops()
        {
            throw new System.NotImplementedException();
        }

        public void AssignShopOwner(int shopId, int customerId)
        {
            throw new System.NotImplementedException();
        }
    }
}